package com.akuma.redmine.service.impl;

import com.akuma.common.util.JsonUtils;
import com.akuma.redmine.entity.TrackerQuery;
import com.akuma.redmine.entity.TrackersQuery;
import com.akuma.redmine.exception.RedMineException;
import com.akuma.redmine.service.ITrackerService;
import com.akuma.redmine.util.RedMineHttpRequest;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by akuma on 2016/10/13.
 *
 * @author akuma
 */
public class TrackerServiceImpl implements ITrackerService {

    public List<TrackerQuery> findAll() {
        Map<String, String> params = new HashMap<String, String>();
        String s = null;
        try {
            s = RedMineHttpRequest.adminGet(params, "trackers.json");
        } catch (Exception e) {
            RedMineException.throwException(e);
        }
        System.out.println(s);
        TrackersQuery trackersQuery = JsonUtils.readValue(s, TrackersQuery.class);
        if (trackersQuery != null) {
            return trackersQuery.getTrackers();
        }
        return null;
    }
}
